package com.software.lineragent.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.software.common.CommonUtils;
import com.software.form.bookingform.dao.BookingForm;
import com.software.form.bookingform.dao.BookingFormTransaction;

public class ConfirmServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		BookingFormTransaction bft = (BookingFormTransaction) CommonUtils.getBean("bookingFormTransaction");
		try {
			int id = (Integer) request.getSession().getAttribute("booking_id");
			if(bft.updateStatusById(id, -1)){
				CommonUtils.outputJsonData(1, response);
			}else{
				CommonUtils.outputJsonData(0, response);
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		JSONObject o = CommonUtils.readJSONStringFromRequestBody(request, response);
		BookingFormTransaction bft = (BookingFormTransaction) CommonUtils.getBean("bookingFormTransaction");
		try {
			String no = o.getString("no");
			int id = (Integer) request.getSession().getAttribute("booking_id");
			if(bft.updateNoById(id, no)){
				bft.updateStatusById(id, 1);
				CommonUtils.outputJsonData(1, response);
			}else{
				CommonUtils.outputJsonData(0, response);
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
